<!DOCTYPE html><html lang="zh-CN"><head>
  <meta charset="utf-8">
  <meta name="viewport" content="width=device-width">
  <title>months | Moment.js &#x6587;&#x6863;</title>
  <link rel="stylesheet" href="static/css/style.css">
  <link rel="shortcut icon" href="http://momentjs.cn/static/img/moment-favicon.png">
  <link rel="stylesheet" href="static/css/atom-one-light.min.css">
</head>
<body class="is-moment">
  <div class="hero hero-oneline">
    <div class="hero-centered">
      <h1>months</h1>
    </div>
  </div>
  <div id="api-section-__FILENAME__">
    <div id="content" class="clearfix">
  
      <div id="column1" data-id="__ID__" class="interior">
        <header>
          <!-- <h1>months</h1> -->
          <div id="gtoc">
            <ul>
              <!-- <li>v</li> -->
              <li>
                <a href="index.html#/customization/month-names/" name="toc">&#x8FD4;&#x56DE;&#x4E0A;&#x5C42;&#x6587;&#x6863;</a>
              </li>
              <li style="border: none;">
                <a href="javascript:window.open('https://github.com/momentjscn/moment-docs-cn/edit/master/moment/07-customization/01-month-names.md');" rel="nofollow" target="_blank">&#x63D0;&#x4EA4;&#x4FEE;&#x6539;</a>
              </li>
              <!-- <li>
                <a href="/search__SEARCH_PARAM__" name="toc">搜索</a>
              </li> -->
            </ul>
          </div>
          <hr>
        </header>

        <div id="biz_item"></div>
  
        <div id="apicontent">
          <div id="content_left">
							<div class="docs-method-signature">
								<pre><code class="language-js">// &#x4ECE; 2.12.0 &#x5F00;&#x59CB;
moment.updateLocale(&apos;en&apos;, {
    months : String[]
});
moment.updateLocale(&apos;en&apos;, {
    months : Function
});
moment.updateLocale(&apos;en&apos;, {
    months : {
        format : String[],
        standalone : String[]
    }
});
// &#x4ECE; 2.11.0 &#x5F00;&#x59CB;
moment.locale(&apos;en&apos;, {
    months : {
        format : String[],
        standalone : String[]
    }
});
// &#x4ECE; 2.8.1 &#x81F3; 2.11.2
moment.locale(&apos;en&apos;, {
    months : String[]
});
moment.locale(&apos;en&apos;, {
    months : Function
});

// &#x5E9F;&#x5F03;&#x4E8E; 2.8.1
moment.lang(&apos;en&apos;, {
    months : String[]
});
moment.lang(&apos;en&apos;, {
    months : Function
});
</code></pre>

							</div>
<p><code>Locale#months</code> &#x5E94;&#x662F;&#x6708;&#x4EFD;&#x540D;&#x79F0;&#x7684;&#x6570;&#x7EC4;&#x3002;</p>
<pre><code class="language-javascript">moment.updateLocale(&apos;en&apos;, {
    months : [
        &quot;January&quot;, &quot;February&quot;, &quot;March&quot;, &quot;April&quot;, &quot;May&quot;, &quot;June&quot;, &quot;July&quot;,
        &quot;August&quot;, &quot;September&quot;, &quot;October&quot;, &quot;November&quot;, &quot;December&quot;
    ]
});
</code></pre>
<p>&#x5982;&#x679C;&#x9700;&#x8981;&#x66F4;&#x591A;&#x5904;&#x7406;&#x6765;&#x8BA1;&#x7B97;&#x6708;&#x4EFD;&#x7684;&#x540D;&#x79F0;&#xFF08;&#x4F8B;&#x5982;&#xFF0C;&#x5982;&#x679C;&#x4E0D;&#x540C;&#x683C;&#x5F0F;&#x7684;&#x8BED;&#x6CD5;&#x4E0D;&#x540C;&#xFF09;&#xFF0C;&#x5219; <code>Locale#months</code> &#x53EF;&#x4EE5;&#x662F;&#x5177;&#x6709;&#x4EE5;&#x4E0B;&#x7B7E;&#x540D;&#x7684;&#x51FD;&#x6570;&#x3002;
&#x5B83;&#x5E94;&#x59CB;&#x7EC8;&#x8FD4;&#x56DE;&#x6708;&#x4EFD;&#x7684;&#x540D;&#x79F0;&#x3002;</p>
<pre><code class="language-javascript">moment.updateLocale(&apos;en&apos;, {
    months : function (momentToFormat, format) {
        // momentToFormat &#x662F;&#x5F53;&#x524D;&#x6B63;&#x5728;&#x88AB;&#x683C;&#x5F0F;&#x5316;&#x7684; moment&#x3002;
        // format &#x662F;&#x683C;&#x5F0F;&#x5316;&#x5B57;&#x7B26;&#x4E32;&#x3002;
        if (/^MMMM/.test(format)) { // &#x5982;&#x679C;&#x683C;&#x5F0F;&#x4EE5; &apos;MMMM&apos; &#x5F00;&#x5934;&#x3002;
            return nominative[momentToFormat.month()];
        } else {
            return subjective[momentToFormat.month()];
        }
    }
});
</code></pre>
<p>&#x4ECE; <strong>2.11.0</strong> &#x7248;&#x672C;&#x5F00;&#x59CB;&#xFF0C;&#x6708;&#x4EFD;&#x4E5F;&#x53EF;&#x4EE5;&#x662F;&#x4E00;&#x4E2A;&#x5BF9;&#x8C61;&#xFF0C;&#x6307;&#x5B9A; <code>standalone</code> &#x548C; <code>format</code> &#x7684;&#x5F62;&#x5F0F;&#xFF08;&#x4E3B;&#x683C;&#x548C;&#x5BBE;&#x683C;&#xFF09;&#x3002;
&#x5728;&#x683C;&#x5F0F;&#x4E0A;&#x8FD0;&#x884C;&#x4EE5;&#x68C0;&#x67E5;&#x662F;&#x5426;&#x4F7F;&#x7528; <code>format</code> &#x5F62;&#x5F0F;&#x7684;&#x6B63;&#x5219;&#x8868;&#x8FBE;&#x5F0F;&#x662F; <code>/D[oD]?(\[[^\[\]]*\]|\s+)+MMMM?/</code>&#x3002;
&#x4ECE; <strong>2.14.0</strong> &#x7248;&#x672C;&#x5F00;&#x59CB;&#xFF0C;&#x53EF;&#x4EE5;&#x4F7F;&#x7528; <code>isFormat</code> &#x952E;&#x6307;&#x5B9A;&#x53E6;&#x4E00;&#x4E2A;&#x3002;</p>
<pre><code class="language-javascript">moment.updateLocale(&apos;en&apos;, {
    months : {
         format: &apos;sausio_vasario_kovo_baland&#x17E;io_gegu&#x17E;&#x117;s_bir&#x17E;elio_liepos_rugpj&#x16B;&#x10D;io_rugs&#x117;jo_spalio_lapkri&#x10D;io_gruod&#x17E;io&apos;.split(&apos;_&apos;),
         standalone: &apos;sausis_vasaris_kovas_balandis_gegu&#x17E;&#x117;_bir&#x17E;elis_liepa_rugpj&#x16B;tis_rugs&#x117;jis_spalis_lapkritis_gruodis&apos;.split(&apos;_&apos;),
         isFormat: /D[oD]?(\[[^\[\]]*\]|\s+)+MMMM?|MMMM?(\[[^\[\]]*\]|\s+)+D[oD]?/  // from 2.14.0
    }
});
</code></pre>
					</div>
          <div id="content_right">
							<div class="docs-method-signature">
								<pre><code class="language-js">// From 2.12.0 onward
moment.updateLocale(&apos;en&apos;, {
    months : String[]
});
moment.updateLocale(&apos;en&apos;, {
    months : Function
});
moment.updateLocale(&apos;en&apos;, {
    months : {
        format : String[],
        standalone : String[]
    }
});
// From 2.11.0
moment.locale(&apos;en&apos;, {
    months : {
        format : String[],
        standalone : String[]
    }
});
// From 2.8.1 to 2.11.2
moment.locale(&apos;en&apos;, {
    months : String[]
});
moment.locale(&apos;en&apos;, {
    months : Function
});

// Deprecated in 2.8.1
moment.lang(&apos;en&apos;, {
    months : String[]
});
moment.lang(&apos;en&apos;, {
    months : Function
});
</code></pre>

							</div>
<p><code>Locale#months</code> should be an array of the month names.</p>
<pre><code class="language-javascript">moment.updateLocale(&apos;en&apos;, {
    months : [
        &quot;January&quot;, &quot;February&quot;, &quot;March&quot;, &quot;April&quot;, &quot;May&quot;, &quot;June&quot;, &quot;July&quot;,
        &quot;August&quot;, &quot;September&quot;, &quot;October&quot;, &quot;November&quot;, &quot;December&quot;
    ]
});
</code></pre>
<p>If you need more processing to calculate the name of the month, (for example, if there is different grammar for different formats), <code>Locale#months</code> can be a function with the following signature. It should always return a month name.</p>
<pre><code class="language-javascript">moment.updateLocale(&apos;en&apos;, {
    months : function (momentToFormat, format) {
        // momentToFormat is the moment currently being formatted
        // format is the formatting string
        if (/^MMMM/.test(format)) { // if the format starts with &apos;MMMM&apos;
            return nominative[momentToFormat.month()];
        } else {
            return subjective[momentToFormat.month()];
        }
    }
});
</code></pre>
<p>From version <strong>2.11.0</strong> months can also be an object, specifying <code>standalone</code> and <code>format</code> forms (nominative and accusative). The regular expression that is run on the format to check whether to use the <code>format</code> form is <code>/D[oD]?(\[[^\[\]]*\]|\s+)+MMMM?/</code>. From version <strong>2.14.0</strong> a different one can be specified with the <code>isFormat</code> key.</p>
<pre><code class="language-javascript">moment.updateLocale(&apos;en&apos;, {
    months : {
         format: &apos;sausio_vasario_kovo_baland&#x17E;io_gegu&#x17E;&#x117;s_bir&#x17E;elio_liepos_rugpj&#x16B;&#x10D;io_rugs&#x117;jo_spalio_lapkri&#x10D;io_gruod&#x17E;io&apos;.split(&apos;_&apos;),
         standalone: &apos;sausis_vasaris_kovas_balandis_gegu&#x17E;&#x117;_bir&#x17E;elis_liepa_rugpj&#x16B;tis_rugs&#x117;jis_spalis_lapkritis_gruodis&apos;.split(&apos;_&apos;),
         isFormat: /D[oD]?(\[[^\[\]]*\]|\s+)+MMMM?|MMMM?(\[[^\[\]]*\]|\s+)+D[oD]?/  // from 2.14.0
    }
});
</code></pre>
					</div>
          <div></div>
        </div>
      </div>
    </div>
  </div>
  
  <script src="static/js/highlight.min.js"></script>
  <script src="static/js/javascript.min.js"></script>
  <script>hljs.initHighlightingOnLoad();</script>
  <script>var _hmt = _hmt || []; (function () { var hm = document.createElement("script"); hm.src = "//hm.baidu.com/hm.js?7a7f78c805fbacc7e075d34f153031aa"; var s = document.getElementsByTagName("script")[0]; s.parentNode.insertBefore(hm, s); })();</script>

  <style>
    .hero-centered {
      margin: 0;
          margin-left: 10px;
    }
#gtoc ul {
  list-style: none;
  margin-left: 0;
  line-height: 1.5rem;
  padding: 0;
}
#gtoc>ul>li {
  display: inline;
  border-right: 1px solid #000;
  margin-right: .4rem;
  padding-right: .4rem;
}
#gtoc>ul>li>a {
  color: #61b2a7;
}
#content_left {
  width: 49%;float: left;border-right: 1px solid #eee;    padding-right: 2%;
}
#content_right {
float: left;width: 48%;margin-left: 3%;
}
#column1 {
  padding: 0 2rem;
}
  </style>


</body></html>